package com.ymttest.database.sqlwapper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymatou.iapi.couponmanage.parameter.queryBagBean;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCoupon;
import com.ymttest.database.model.coupon;
import com.ymttest.database.model.couponbag;
import com.ymttest.database.model.couponbatch;
import com.ymttest.utils.EnvSetup;

public class couponbagWapper {
	SqlManager manager;

    public couponbagWapper() {
        manager = new SqlManager("mysqlcoupon" + EnvSetup.getEnv());
    }

    public couponbag selectByPrimaryKey(String bagCode) {
    	couponbag couponbag=new couponbag();
        List<couponbag> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.couponbagMapper.selectByPrimaryKey",
                        bagCode);
        manager.commit();
        if(result.size()>0)
        {
        	couponbag=result.get(0);
        }
        return couponbag;
    }
    
    public List<couponbag> selectQueryBag(queryBagBean querybagBean) {
    	Map map=new HashMap<String,Object>();
    	 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	map.put("bagCode", querybagBean.getBagCode());
    	map.put("conversionCode", querybagBean.getConversionCode());
    	map.put("acquireMethod", querybagBean.getAcquireMethod());
    	map.put("effectiveType", querybagBean.getEffectiveType());
    	map.put("createTimeStart", sdf.format(querybagBean.getCreateTimeStart()));
    	map.put("createTimeEnd", sdf.format(querybagBean.getCreateTimeEnd()));
    	map.put("applyDepartment", querybagBean.getApplyDepartment());
    	map.put("pagesizeStart", querybagBean.getPagesizeStart());
    	map.put("pagesizeEnd", querybagBean.getPagesizeEnd());
    	List<couponbag> result=null;
        if(querybagBean.getConversionCode()==null)
        {
        	result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.couponbagMapper.selectQueryBag",
                        map);
        }else
        {
        	result = manager
                    .getSelectResults(
                            "com.ymttest.database.mapping.couponbagMapper.selectQueryBagByConversionCode",
                            map);
        }
        manager.commit();
        return result; 
    }

    public List<couponbag> selectByBagCodes(List<String> bagCodes) {
        List<couponbag> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.couponbagMapper.selectByBagCodes",
                        bagCodes);
        manager.commit();
        return result;
    }
    
    public void setAcquireStartTime(String couponbag, Date acquireStartTime) {
        Map m = new HashMap();
        m.put("couponbag", couponbag);
        m.put("acquireStartTime", acquireStartTime);
        manager
                .update(
                        "com.ymttest.database.mapping.couponbagMapper.setAcquireStartTime",
                        m);
        manager.commit();
    }
    
    public void setAcquireEndTime(String couponbag, Date acquireEndTime) {
        Map m = new HashMap();
        m.put("couponbag", couponbag);
        m.put("acquireEndTime", acquireEndTime);
        manager
                .update(
                        "com.ymttest.database.mapping.couponbagMapper.setAcquireEndTime",
                        m);
        manager.commit();
    }
    
    

    public static void main(String[] args) {
//        YmtCouponWapper test = new YmtCouponWapper();
//
//        System.out.println(test.useCoupon(20238699, "AIL7PT3W1",null));
//        // test.insertYmtCouponSetting(3,11);
//        // Logger.debug(test.getLastYmtCouponSettingId());
    }
}
